package edu.usc.trials;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

import edu.usc.utils.FileUtils;

public class SampleTest {

	public static String folderURL = "C:\\Ramesh\\works\\projects\\java_ws\\StorySummerizer\\trainingsummary";

	public static void main(String[] args) {

		ArrayList<String> files = FileUtils.listAllFilesInDirectory(folderURL);
		ArrayList<String> wordsNone = new ArrayList<>();
		ArrayList<String> wordsOthers = new ArrayList<>();

		ArrayList<String> ccWord = new ArrayList<>();
		ArrayList<String> crWord = new ArrayList<>();
		ArrayList<String> rmWord = new ArrayList<>();
		ArrayList<String> drWord = new ArrayList<>();
		ArrayList<String> selfLWord = new ArrayList<>();
		ArrayList<String> socLWord = new ArrayList<>();
		ArrayList<String> scWord = new ArrayList<>();
		ArrayList<String> erWord = new ArrayList<>();
		ArrayList<String> suWord = new ArrayList<>();
		ArrayList<String> hrWord = new ArrayList<>();
		ArrayList<String> selfRWord = new ArrayList<>();

		for(String file: files) {
			ArrayList<String> contents = 
					FileUtils.contentsOfTheFileAsList(file);
			for(String line: contents) {
				String[] mods = line.split("\t");
				String cleanSentence = FileUtils.cleanSentences(mods[1]);
				String stoppedTemp = 
						FileUtils.removeStopWordsString(cleanSentence, null);
				stoppedTemp = stoppedTemp.replaceAll("[^\\p{Alpha} ]", "");
				String stemmedTemp =
						FileUtils.stemString(stoppedTemp);
				String[] splits = stemmedTemp.split(" ");
				if(mods[2].equals("None")) { 
					for(int i=0; i < splits.length; i++) {
						wordsNone.add(splits[i]);
					}
				} else {
					for(int i=0; i < splits.length; i++) {
						wordsOthers.add(splits[i]);
					}
					if(mods[2].equals("CR")) {
						for(int i=0; i < splits.length; i++) {
							crWord.add(splits[i]);
						}
					} 
					if(mods[2].equals("ER")) {
						for(int i=0; i < splits.length; i++) {
							erWord.add(splits[i]);
						}
					}
					if(mods[2].equals("DR")) {
						for(int i=0; i < splits.length; i++) {
							drWord.add(splits[i]);
						}
					}
					if(mods[2].equals("HR")) {
						for(int i=0; i < splits.length; i++) {
							hrWord.add(splits[i]);
						}
					}
					if(mods[2].equals("SocL")) {
						for(int i=0; i < splits.length; i++) {
							socLWord.add(splits[i]);
						}
					}
					if(mods[2].equals("SelfL")) {
						for(int i=0; i < splits.length; i++) {
							selfLWord.add(splits[i]);
						}
					}
					if(mods[2].equals("SelfR")) {
						for(int i=0; i < splits.length; i++) {
							selfRWord.add(splits[i]);
						}
					}
					if(mods[2].equals("SC")) {
						for(int i=0; i < splits.length; i++) {
							scWord.add(splits[i]);
						}
					}
					if(mods[2].equals("SU")) {
						for(int i=0; i < splits.length; i++) {
							suWord.add(splits[i]);
						}
					}
					if(mods[2].equals("CC")) {
						for(int i=0; i < splits.length; i++) {
							ccWord.add(splits[i]);
						}
					}
					if(mods[2].equals("RM")) {
						for(int i=0; i < splits.length; i++) {
							rmWord.add(splits[i]);
						}
					}
				}
			}
		}

		HashMap<String, Integer> wNoneCounts = FileUtils.getWordCounts(wordsNone);
		HashMap<String, Integer> wOthersCounts = FileUtils.getWordCounts(wordsOthers);

		Set<String> wordsInNone = wNoneCounts.keySet();
		Set<String> wordsInOthers = wOthersCounts.keySet();

		TreeSet<String> intersectNone = new TreeSet<>();
		TreeSet<String> intersectOthers = new TreeSet<>();

		for(String s: wordsInNone) {
			intersectNone.add(s);
		}
		for(String s: wordsInOthers) {
			intersectOthers.add(s);
		}
		intersectNone.removeAll(wordsInOthers);
		intersectOthers.removeAll(wordsInNone);

		System.out.println("None   : "+intersectNone);
		System.out.println("Others : "+intersectOthers);

		System.out.println("CR : " + crWord);
		System.out.println("CC : " + ccWord);
		System.out.println("HR : " + hrWord);
		System.out.println("SC : " + scWord);
		System.out.println("SelfR : " + selfRWord);
		System.out.println("SocL : " + socLWord);
		System.out.println("SelfR : " + selfRWord);
		System.out.println("SelfL : " + selfLWord);
		System.out.println("RM : " + rmWord);
		System.out.println("SU : " + suWord);

		/*for(String none: intersectNone) {
			FileUtils.writeToFileAlreadyExisting("None", none);
		}
		for(String others: intersectOthers) {
			FileUtils.writeToFileAlreadyExisting("Others", others);
		}*/
		for(String cr: new HashSet<>(crWord)) {
			if(cr.length() > 1){
				FileUtils.writeToFileAlreadyExisting("CR", cr);
			}
		}
		for(String cc: new HashSet<>(ccWord)) {
			if(cc.length() > 1){
				FileUtils.writeToFileAlreadyExisting("CC", cc);
			}
		}
		for(String hr: new HashSet<>(hrWord)) {
			if(hr.length() > 1){
				FileUtils.writeToFileAlreadyExisting("HR", hr);
			}
		}
		for(String dr: new HashSet<>(drWord)) {
			if(dr.length() > 1){
				FileUtils.writeToFileAlreadyExisting("DR", dr);
			}
		}
		for(String sc: new HashSet<>(scWord)) {
			if(sc.length() > 1){
				FileUtils.writeToFileAlreadyExisting("SC", sc);
			}
		}
		for(String su: new HashSet<>(suWord)) {
			if(su.length() > 1){
				FileUtils.writeToFileAlreadyExisting("SU", su);
			}
		}
		for(String socL: new HashSet<>(socLWord)) {
			if(socL.length() > 1){
				FileUtils.writeToFileAlreadyExisting("SocL", socL);
			}
		}
		for(String selfR: new HashSet<>(selfRWord)) {
			if(selfR.length() > 1){
				FileUtils.writeToFileAlreadyExisting("SelfR", selfR);
			}
		}
		for(String selfL: new HashSet<>(selfLWord)) {
			if(selfL.length() > 1){
				FileUtils.writeToFileAlreadyExisting("SelfL", selfL);
			}
		}
		for(String er: new HashSet<>(erWord)) {
			if(er.length() > 1){
				FileUtils.writeToFileAlreadyExisting("ER", er);
			}
		}
		for(String rm: new HashSet<>(selfLWord)) {
			if(rm.length() > 1){
				FileUtils.writeToFileAlreadyExisting("RM", rm);
			}
		}

	}
}
